import i18n from '../../i18n'
const t = i18n.global.t
export const options = [
  {
    label: 'username',
    prop: 'username'
  },
  {
    label: 'email',
    prop: 'email'
  },
  {
    label: 'mobile',
    prop: 'mobile'
  },
  {
    label: 'role_name',
    prop: 'role_name'
  },
  {
    label: 'mg_state',
    prop: 'mg_state',
    width: 100
  },
  {
    label: 'create_time',
    prop: 'create_time'
  },
  {
    label: 'action',
    prop: 'action',
    width: 200
  }
]

export const adduserFormopt = {
  username: '',
  password: '',
  email: '',
  mobile: ''
}
// 自定义邮箱的校验规则
const validatoremail = (rule: any, value: any, callback: any) => {
  const regmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/
  if (regmail.test(value)) return callback()
  callback(new Error(t('rules.emile')))
}
// 自定义手机号的校验规则
const validatormobil = (rule: any, value: any, callback: any) => {
  const regmobil = /^(0|86|17951)?(13[0-9]|15[0123456789]|17[678]|18[0-9]|14[57])[0-9]{8}$/
  if (regmobil.test(value)) return callback()
  callback(new Error(t('rules.mobile')))
}
export const adduserrulesopt = {
  username: [
    { required: true, message: 'Please input username name', trigger: 'blur' },
    { min: 4, max: 10, message: 'Length should be 4 to 10', trigger: 'blur' }
  ],
  password: [
    { required: true, message: 'Please input password', trigger: 'blur' },
    { min: 3, max: 11, message: 'Length should be 3-11', trigger: 'blur' }
  ],
  email: [
    { required: true, message: 'Please input email', trigger: 'blur' },
    { validator: validatoremail, trigger: 'blur' }
  ],
  mobile: [
    { required: true, message: 'Please input mobile', trigger: 'blur' },
    { validator: validatormobil, trigger: 'blur' }
  ]
}
